package com.wa.config;

import com.corundumstudio.socketio.SocketIONamespace;
import com.corundumstudio.socketio.SocketIOServer;
import com.wa.constants.NameSpaceBeanNameConstant;
import com.wa.enums.NameSpaceEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * 命名空间管理, 每个工程拥有自己独立的命名空间, 需要手动创建, 命名空间需要添加自己的事件监听器, 主命名空间配置的事件监听器不会被继承
 */
//@Configuration
//@ConditionalOnBean(value = WebSocketConfig.class)
public class WebSocketNameSpaceConfig {

    /**
     * logger
     */
    private static final Logger logger = LoggerFactory.getLogger(WebSocketNameSpaceConfig.class);

    /**
     * socketIOServer
     */
    private final SocketIOServer socketIOServer;

    @Autowired
    public WebSocketNameSpaceConfig(SocketIOServer socketIOServer) {
        this.socketIOServer = socketIOServer;
    }

    @Bean(value = NameSpaceBeanNameConstant.BOM)
    public SocketIONamespace bomNamespace() {
        logger.debug("------------------------------>创建bom命名空间<------------------------------");
        return socketIOServer.addNamespace(NameSpaceEnum.BOM.getCodeEn());
    }

    @Bean(value = NameSpaceBeanNameConstant.WEBSITE)
    public SocketIONamespace websiteNamespace() {
        logger.debug("------------------------------>创建website命名空间<------------------------------");
        return socketIOServer.addNamespace(NameSpaceEnum.WEBSITE.getCodeEn());
    }

    @Bean(value = NameSpaceBeanNameConstant.BOSS)
    public SocketIONamespace bossNamespace() {
        logger.debug("------------------------------>创建boss命名空间<------------------------------");
        return socketIOServer.addNamespace(NameSpaceEnum.BOSS.getCodeEn());
    }

    @Bean(value = NameSpaceBeanNameConstant.PRODUCT)
    public SocketIONamespace productNamespace() {
        logger.debug("------------------------------>创建product命名空间<------------------------------");
        return socketIOServer.addNamespace(NameSpaceEnum.PRODUCT.getCodeEn());
    }

    @Bean(value = NameSpaceBeanNameConstant.BOM_SAAS)
    public SocketIONamespace bomSaasNamespace() {
        logger.debug("------------------------------>创建bomSaas命名空间<------------------------------");
        return socketIOServer.addNamespace(NameSpaceEnum.BOM_SAAS.getCodeEn());
    }

}
